import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_jpf_core/util/colors_util.dart';

class SelectView extends StatefulWidget {
  bool isSelect = false;
  String title;
  Function(bool) onSelectChanged;
  BoxConstraints constraints;

  double radius;

  Color defaultBgColor;
  Color activeBgColor;
  Color defaultTxColor;
  Color activeTxColor;

  SelectView(this.title, {this.isSelect = false,this.onSelectChanged,this.constraints,this.activeTxColor = Colors.white,this.activeBgColor = const Color(0xff477bfc),this.defaultBgColor = const Color(0xffedeeef),this.defaultTxColor = ColorsUtil.black_666,this.radius = 4});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return SelectViewState();
  }
}

class SelectViewState extends State<SelectView> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    Color bgColor;
    TextStyle titleStyle;
    if(widget.isSelect){
      bgColor = widget.activeBgColor;
      titleStyle = TextStyle(color: widget.activeTxColor);
    }else{
      bgColor = widget.defaultBgColor;
      titleStyle = TextStyle(color: widget.defaultTxColor);
    }
    return GestureDetector(child: Container(
      alignment: Alignment.center,
      child: Text(widget.title ?? "",style: titleStyle,textAlign: TextAlign.center,),
      padding: EdgeInsets.all(5),
      constraints: widget.constraints,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(widget.radius),
        color: bgColor,
      ),
    ),onTap: (){
      setState(() {
        widget.isSelect = !widget.isSelect;
        if(widget.onSelectChanged != null){
          widget.onSelectChanged(widget.isSelect);
        }
      });
    },);
  }

}
